home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 220 / 220.xpi / chrome / flashgot.jar / content / flashgot / chooser.js < prev    next >
Encoding:
Text File  |  2010-01-24  |  3.1 KB  |  98 lines

  1. /***** BEGIN LICENSE BLOCK *****
  2.  
  3.     FlashGot - a Firefox extension for external download managers integration
  4.     Copyright (C) 2004-2009 Giorgio Maone - g.maone@informaction.com
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.                              
  20. ***** END LICENSE BLOCK *****/
  21.  
  22. const CI = Components.interfaces;
  23. const CC = Components.classes;
  24.  
  25. var Chooser = {
  26.   init: function() {
  27.     this.dialog = document.documentElement;
  28.    
  29.     this.params = window.arguments[0];
  30.     this.params.choosenDir = this.params.initialDir;
  31.     
  32.     this.dialog.setAttribute("title", this.params.title);
  33.     document.getElementById("destLabel").setAttribute("value",
  34.       this.destFolderLabel = gFlashGotService.getString("ph.FOLDER")
  35.     );
  36.     if (this.params.choosenDir) {
  37.       this.sync();
  38.     } else {
  39.       this.browse();
  40.     }
  41.   },
  42.   
  43.   sync: function() {
  44.     var t = document.getElementById("dest");
  45.     var d = this.params.choosenDir;
  46.     if (d && t.value != d.path) {
  47.       t.value = d.path;
  48.     } 
  49.     this.dialog.getButton("accept").setAttribute("disabled", !d);
  50.   },
  51.   
  52.   folderChanged: function(t) {
  53.     var path = t.value;
  54.     this.params.choosenDir = null;      
  55.     try {
  56.       var d = CC["@mozilla.org/file/local;1"].createInstance(CI.nsILocalFile);
  57.       d.initWithPath(t.value);
  58.       if (!d.exists() || d.isDirectory())
  59.         this.params.choosenDir = d;      
  60.     } catch(e) {
  61.     }
  62.     this.sync();
  63.   },
  64.  
  65.   browse: function() {
  66.     const fp = CC["@mozilla.org/filepicker;1"].createInstance(CI.nsIFilePicker);
  67.    
  68.     fp.init(window, this.params.title + " - " + this.destFolderLabel, CI.nsIFilePicker.modeGetFolder);
  69.     var d = this.params.choosenDir || this.params.initialDir;
  70.     try {
  71.       if (d && (d.exists() || (d = d.parent).exists()) && d.isDirectory()) {
  72.         fp.displayDirectory = d;
  73.       }
  74.     } catch (ex) { gFlashGotService.log(ex); }
  75.     
  76.     fp.appendFilters(CI.nsIFilePicker.filterAll);
  77.     
  78.     if (fp.show() == CI.nsIFilePicker.returnOK) {
  79.       this.params.choosenDir = fp.file;
  80.       this.sync();
  81.     }
  82.   },
  83.   
  84.   accept: function() {
  85.     // create directory if it does not exist
  86.     var d = this.params.choosenDir;
  87.     if (d && !d.exists()) {
  88.       var permissions = d.parent.exists() ? d.parent.permissions : 0600;
  89.       try {
  90.         d.create(CI.nsIFile.DIRECTORY_TYPE, permissions);
  91.       } catch(e) {
  92.       }
  93.     }
  94.   },
  95.   cancel: function() {
  96.     this.params.choosenDir = null;
  97.   }
  98. }